package com.json;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.File;
import java.io.IOException;

public class JsonIdExtractor {
    public static void main(String[] args) {
        try {
            // 创建 ObjectMapper 实例
            ObjectMapper mapper = new ObjectMapper();

            // 读取 JSON 文件
            JsonNode rootNode = mapper.readTree(new File("C:\\Users\\hcf\\IdeaProjects\\dache-test\\service-hi\\src\\main\\resources\\testJson.json"));

            // 获取 data 数组
            JsonNode dataArray = rootNode.path("data");

            // 遍历 data 数组，提取所有 id 字段
            for (JsonNode node : dataArray) {
                JsonNode idNode = node.path("id");
                if (!idNode.isMissingNode()) {
                    System.out.println(idNode.asLong());
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
